home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / helpful MPW scripts / MakeTheFolder < prev    next >
Encoding:
Text File  |  1993-09-17  |  4.4 KB  |  138 lines  |  [TEXT/MPS ]

  1. ###################################################################################################
  2. #
  3. #    Copyright © 1990 Apple Computer, Inc. All rights reserved.
  4. #    Copyright © 1990 Kevin O'Mahoney,     All rights reserved.
  5. #
  6. #    File: MakeTheFolder
  7. #
  8. #
  9. ###################################################################################################
  10. #
  11. #    Abstract:
  12. #
  13. #    This script was developed to help in the building of BART project as part of the Service Tools
  14. #    diagnostic projects.  
  15. #
  16. #    This script accepts one input parameter.  This is the name of a folder to be created.  Whereas
  17. #    the MPW command NewFolder will also create folders, the NewFolder command will not create a 
  18. #    named folder if all of it's parent folders do not already exist.  This script will insure all
  19. #    folders in the path exist.  So this script may be called once using the full pathname of the 
  20. #    desired folder and this script will create all needed parent folders along the path and then
  21. #     the target folder itself.
  22. #
  23. #    If the folder already exists then no action is taken.
  24. #
  25. ###################################################################################################
  26. #
  27. #    Usage:
  28. #        MakeTheFolder folderName
  29. #
  30. #
  31. ###################################################################################################
  32. #
  33. #    Change History:
  34. #
  35. # 11 Nov 1991 - KOM    -    new today
  36. # 19 Nov 1991 - KOM    -    rewritten and made more robust in error handling
  37. #
  38. ###################################################################################################
  39.  
  40. Set ErrorCode 0;                            # no errors yet
  41.  
  42. #-------------------------------------------# turn off echo
  43. Set savedEchoState    "{Echo}";
  44. #Set Echo 0;
  45.  
  46. Set UsageString "# Usage - “{0} folderName”"
  47. Set EchoPrefix "#    {0} - ";
  48.  
  49. #Echo " "
  50. #Echo "{EchoPrefix}Parameters count={#} params=“{Parameters}”";
  51.  
  52. If ( {#} == 0 )
  53.     Echo "### {0} - no folder name specified." > Dev:StdErr
  54.     Echo "{UsageString}" > Dev:StdErr
  55.     Set ErrorCode 1;
  56. Else If ( {#} > 1 )
  57.     Echo "### {0} - too many parameters." > Dev:StdErr
  58.     Echo "{UsageString}" > Dev:StdErr
  59.     Set ErrorCode 2;
  60. End;
  61.  
  62. #---------------------------------------------------------------------------------------------------
  63. If "{1}" =~ /:(≈)®1/                # strip off leading colon till we need it
  64.     Set toFolderName "{®1}";
  65.     #Set kLeadingColon ":";            # remember the leading colon
  66.     Set kLeadingColon "`Directory`"; # remember the leading colon along with the full path name to here
  67. Else
  68.     Set toFolderName "{1}";
  69.     Set kLeadingColon "";            # there was no leading colon
  70. End;
  71.  
  72. #---------------------------------------------------------------------------------------------------
  73. #Echo "{EchoPrefix}toFolderName = “{toFolderName}”, kLeadingColon=“{kLeadingColon}”";
  74. #Echo;
  75.  
  76. #---------------------------------------------------------------------------------------------------
  77. Set kFolderToMake "{toFolderName}";
  78. Set kBuildUpname "";
  79.  
  80. Loop;
  81.     Break If ( {ErrorCode} != 0 );
  82.     Set ®1 "";
  83.     Set ®2 "";
  84.     ( Evaluate "{kFolderToMake}" =~ /([¬:]+:)®1(≈)®2/     ) > Dev:Null;
  85.     Set k1 "{®1}""";
  86.     Set k2 "{®2}""";
  87.     #Echo "{EchoPrefix}(loop) k1 = “{k1}”, k2 = “{k2}”";
  88.  
  89.     Set kBuildUpname "{kBuildUpname}{k1}";
  90.     Set kFolderToMake "{k2}";
  91.     #Echo "{EchoPrefix}(loop2) “{kBuildUpname} - {kFolderToMake}”  kBuildUpname - kFolderToMake ";
  92.     #Echo "{EchoPrefix} - NewFolder {kLeadingColon}{kBuildUpname}";
  93.  
  94.     Loop
  95.         If Not "`Exists "{kLeadingColon}{kBuildUpname}"`"
  96.             #Echo "Creating Folder:    “{kLeadingColon}{kBuildUpname}”.";
  97.             NewFolder "{kLeadingColon}{kBuildUpname}";
  98.             If `Exists "{kLeadingColon}{kBuildUpname}"`        # did we create it?
  99.                 Break;
  100.             Else;
  101.                 Echo "### Error, {0} -    Unable to create target folder, “{kLeadingColon}{kBuildUpname}”.";
  102.                 Set ErrorCode 4;
  103.                 Break;
  104.             End;
  105.     
  106.             Break;
  107.         Else
  108.             If Not "`Exists -d "{kLeadingColon}{kBuildUpname}"`"
  109.                 ( Evaluate "{kLeadingColon}{kBuildUpname}" =~ /(≈)®1:/     ) > Dev:Null;
  110.                 Echo "### Error in {0}: Trying to make folder but found a file “{®1}”."
  111.                 {MAFailed}
  112.                 Set ErrorCode 3;
  113.                 Break;
  114.             Else
  115.                 #Echo "{EchoPrefix}found folder";
  116.                 Break;
  117.             End
  118.         End;
  119.     End;
  120.  
  121.  
  122.  
  123.     If "{k2}" == ""
  124.         #Echo "{EchoPrefix}(loop) break, k2 is blank, no more parent folders."
  125.         Break;
  126.     End;
  127. #Echo;
  128. End; Unset ®1; Unset ®2; 
  129.  
  130. #Echo "{EchoPrefix}(loop) kFolderToMake = “{kFolderToMake}” on the way out of loop.";
  131.  
  132.  
  133. #------------------------------------------------------------# restore echo state
  134. Set Echo "{savedEchoState}";
  135. Unset savedEchoState;
  136.  
  137. #Echo "{EchoPrefix}ErrorCode = “{ErrorCode}”";
  138. Exit {ErrorCode};